package com.ruoyi.loan.product.controller;

import com.ruoyi.common.core.domain.*;
import com.ruoyi.common.core.web.controller.BaseController;
import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.loan.product.domain.TbCategories;
import com.ruoyi.loan.product.domain.TbLoanProducts;
import com.ruoyi.loan.product.service.TbCategoriesService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

import static com.ruoyi.common.core.utils.PageUtils.startPage;

/**
 * @author 张树智
 * @version 1.0
 * @description: CategoriesController
 * @date 2023-01-13 14:38
 */
@RestController
@RequestMapping("/categories")
@ApiOperation("产品类型")
@Slf4j
public class CategoriesController extends BaseController {

    @Resource
    TbCategoriesService tbCategoriesService;

    /**
     * 贷款产品类型添加
     * @param categories
     * @return
     */
    @PostMapping("/add")
    @ApiOperation("贷款类型添加")
    public R add(@RequestBody TbCategories categories){
        return tbCategoriesService.add(categories);
    }

    /**
     * 贷款产品类型修改
     * @param categories
     * @return
     */
    @PostMapping("/update")
    @ApiOperation("贷款产品类型修改")
    public R update(@RequestBody TbCategories categories){
        return tbCategoriesService.updateByCategories(categories);
    }

    /**
     * 贷款产品类型删除
     * @param tbCategoriesIdVo
     * @return
     */
    @PostMapping("/delete")
    @ApiOperation("贷款产品类型删除")
    public R update(@RequestBody TbCategoriesIdVo tbCategoriesIdVo){
        return tbCategoriesService.deleteById(tbCategoriesIdVo);
    }

    /**
     * 产品类型列表
     * @param categoriesVo
     * @return
     */
    @PostMapping("/findPage")
    @ApiOperation("贷款产品类型分页")
    public TableDataInfo findAll(@RequestBody TbCategoriesVo categoriesVo){
        startPage();
        //查询数据
        List<TbCategories> list=tbCategoriesService.findAll(categoriesVo);
        return getDataTable(list);
    }
}
